package com.amir.common.mvp.base;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.amir.common.holder.CommonViewHolder;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.annotation.NonNull;


public abstract class BaseSingleItemTypeRecyclerViewAdapter<T> extends BaseRecyclerViewAdapter<T> {
    private int resId;

    protected abstract void bindData(CommonViewHolder holder, T data, int position);

    public BaseSingleItemTypeRecyclerViewAdapter(Context context, List<T> dataList, int resId) {
        super(context, dataList);
        this.resId = resId;
    }

    @NonNull
    @NotNull
    @Override
    public CommonViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(resId, parent, false);
        return new CommonViewHolder(view);
    }

    @Override
    public final void onBindViewHolder(@NonNull @NotNull CommonViewHolder holder, int position) {
        bindData(holder, fetchData(position), position);
    }

    protected T fetchData(int position) {

        return dataList.get(position);
    }

}
